<template>
    <h2>修改</h2>
    <table class="table table-bordered">
        <tr>
            <td>会员权益名称</td>
            <td>
                <input type="text" placeholder="请输入会员权益名称" v-model="Info.Mr_Name">
            </td>
        </tr>
        <tr>
            <td>会员权益说明</td>
            <td>
                <textarea cols="20" rows="4" placeholder="请输入会员权益说明" v-model="Info.Mr_Info"></textarea>
            </td>
        </tr>
        <tr>
            <td>是否自定义</td>
            <td>
                <input type="radio"  :value="true" v-model="Info.Mr_Iscustom">是
                <input type="radio"  :value="false"  v-model="Info.Mr_Iscustom">否
            </td>
        </tr>
        <tr>
            <td>规则类型</td>
            <td>
                <select  v-model="Info.Mr_RuleType">
                    <option :value="-1">请选择</option>
                    <option :value="1">折扣</option>
                    <option :value="2">延时</option>
                    <option :value="3">餐饮</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>会员权益规则</td>
            <td>
                <textarea cols="20" rows="4" placeholder="请输入会员权益规则"  v-model="Info.Mr_Rule"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;">
                <input type="button" value="保存" @click="add" class="btn btn-primary">
            </td>
            
        </tr>
    </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue'
import { useRouter,useRoute } from 'vue-router';
//创建路由实例
const router=useRouter();
const route=useRoute()
//声明响应式数据
const Info=ref({
  Mr_Id: route.params.id,
  Mr_Name: "",
  Mr_Info: "",
  Mr_Iscustom: true,
  Mr_RuleType: -1,
  Mr_Rule: ""
})
  //创建onMounted 注册周期钩子 页面在加载时会运行的函数
onMounted(()=>{
    fan();
})
const fan = ()=>
{
    axios.get("https://localhost:44376/api/Member/FindShwo?",{
        
        params:{
            id:route.params.id
        
        }
        
        
    })
    .then
    (
        res=>
        {
            Info.value = res.data
        }
    )
}
const add = ()=>
{

    axios.put("https://localhost:44376/api/Member/Update",Info.value)
    .then
    (
        res=>
        {
            if(res.data > 0)
            {
                alert("修改成功");
                router.push("/ShowMember")
            }
            else
            {
                alert("修改失败");
            }
        }
    )
}
</script>